// component/search-capsule/capsule.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    placeholder:{
      type:String,
      value:"请输入内容"
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    navHeight: '',
    statusBarHeight: 0, // 状态栏高度
    searchMarginTop: 0, // 搜索框上边距
    searchWidth: 0, // 搜索框宽度
    searchHeight: 0 // 搜索框高度
  },
  ready: function () {
    let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
    const { top, width, height, right } = menuButtonInfo
    wx.getSystemInfo({
      success: (res) => {
        console.log(res);
        const { statusBarHeight } = res
        const margin = top - statusBarHeight
        this.setData({
          statusBarHeight: statusBarHeight,
          navHeight: (height + statusBarHeight + (margin * 2)),
          searchMarginTop: statusBarHeight + margin, // 状态栏 + 胶囊按钮边距
          searchHeight: height,  // 与胶囊按钮同高
          searchWidth: right - width - 30 // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度，再减去30两边间距
        })
      },
      fail:err=>{
        console.log(err);
      }
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    search(){
      wx.navigateTo({
        url: '/pages/search/search',
      })
    }
  }
})
